package com.koudai.reader.conponment;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.Toast;

import com.koudai.reader.android.R;
import com.koudai.reader.util.Constant;
import com.koudai.reader.util.HttpUtils;
import com.koudai.reader.vo.EndUser;

public class BecameVIPDialog extends Dialog {
    private RelativeLayout vip1;
    private RelativeLayout vip2;
    private RelativeLayout vip3;
    private RelativeLayout vip4;
    private RelativeLayout vip5;
    
    Handler handler = new Handler();
    
    public BecameVIPDialog(final Context context) {
        super(context);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        
        setContentView(R.layout.became_vip);
        
        vip1 = (RelativeLayout) findViewById(R.id.vip_1);
        vip2 = (RelativeLayout) findViewById(R.id.vip_2);
        vip3 = (RelativeLayout) findViewById(R.id.vip_3);
        vip4 = (RelativeLayout) findViewById(R.id.vip_4);
        vip5 = (RelativeLayout) findViewById(R.id.vip_5);
        
        vip1.setOnClickListener(new GotoPayOnclickListener((Activity)context, 1500, "vip_one"));
        vip2.setOnClickListener(new GotoPayOnclickListener((Activity)context, 4300, "vip_three"));
        vip3.setOnClickListener(new GotoPayOnclickListener((Activity)context, 8500, "vip_six"));
        vip4.setOnClickListener(new GotoPayOnclickListener((Activity)context, 13500, "vip_twelve"));
        
        vip5.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View paramView) {
                
                if (EndUser.getInstance().getGold() >= Math.abs(Constant.operation.get("vip_one"))) {
                    new Thread(new Runnable() {
                        
                        @Override
                        public void run() {
                            
                            if(HttpUtils.gold2VIP()){
                                try {
                                    HttpUtils.requestUserinfo(context);
                                } catch (Exception e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                                handler.post(new Runnable() {
                                    
                                    @Override
                                    public void run() {
                                        
                                        Toast.makeText(context, "感谢您的支持，尊敬的VIP用户", Toast.LENGTH_LONG).show();
                                        
                                    }
                                });
                            }
                        }
                    }).start();
                } else {
                    Toast.makeText(context, "您的积分还不够，谢谢您的支持", Toast.LENGTH_LONG).show();
                }
            }
        });
    }

}
